﻿using System;
using Ext.Net;

namespace ERP.Modules
{
    public partial class MCK_TimeKeeper : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                GetComboBox();
            }
        }
        
        protected void StoreTimeKeeper_RefreshData(object sender, StoreReadDataEventArgs e)
        {

        }

        protected void StoreTimeKeeperDetail_RefreshData(object sender, StoreReadDataEventArgs e)
        {

        }

        protected void btnTimeKeeper_Click(object sender, DirectEventArgs e)
        {
            if (cbMonth.SelectedItem.Value != null && cbSchClass.SelectedItem.Value != null)
            {
                GetData();
            }
        }

        protected void TimeKeeperDblClick(object sender, DirectEventArgs e)
        {
            int Month = int.Parse(e.ExtraParams["Month"]);
            string Employee_ID = e.ExtraParams["Employee_ID"];
            int SchClass_ID = int.Parse(e.ExtraParams["SchClass_ID"]);
            GetDataDetail(Month, Employee_ID, SchClass_ID);
            WindowsTimeKeeperDetail.Show();
        }
        #region

        void GetData()
        {
            var dt = BLL.MCK_BLL.GetTimeKeeper(int.Parse(cbMonth.SelectedItem.Value), int.Parse(cbSchClass.SelectedItem.Value));
            if (dt != null && dt.Rows.Count > 0)
            {
                StoreTimeKeeper.DataSource = dt;
                StoreTimeKeeper.DataBind();
            }
        }

        void GetDataDetail(int month, string employee, int schclass)
        {
            var dt = BLL.MCK_BLL.GetCheckInOutDetail(month, employee, schclass);
            if (dt != null && dt.Rows.Count > 0)
            {
                StoreTimeKeeperDetail.DataSource = dt;
                StoreTimeKeeperDetail.DataBind();
                WindowsTimeKeeperDetail.Title = "Chi tiết chấm công nhân viên: " + dt.Rows[0]["Bank_Code"] + ", " + dt.Rows[0]["FullName"] + ", " + dt.Rows[0]["SchClass_Name"] + ", Tháng " + dt.Rows[0]["Month"];
            }
        }

        void GetComboBox()
        {
            var dtschclass = BLL.MCK_SchClass_BLL.GetData_MCK_SchClass(string.Empty);
            if (dtschclass != null && dtschclass.Rows.Count > 0)
            {
                StoreShclass.DataSource = dtschclass;
                StoreShclass.DataBind();
            }
        }
        #endregion

        #region Search
        protected void SearchTimeKeeper_Event(object sender, DirectEventArgs e)
        {

        }

        protected void SearchTimeKeeperDetail_Event(object sender, DirectEventArgs e)
        {

        } 
        #endregion
    }
}